import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'p43.settings')
django.setup(set_prefix=False)

# 开始测试
'''验证调取持久化的数据
对应视图 employee/views.py session2'''
from django.contrib.sessions.models import Session
session_instance = Session.objects.get(pk='osoeo7f16xhlm1mdzj8rl4zr3m007zkt')
print(session_instance.__dict__)
print(session_instance.session_key)   # id
print(session_instance.session_data)  # 序列化后的数据 data值 小字典
print(session_instance.expire_date)   # 过期时间
print(session_instance.get_decoded())  # 反序列化为可识别的字典
'''
{'_state': <django.db.models.base.ModelState object at 0x000000000461D0D0>, 
    'session_key': 'osoeo7f16xhlm1mdzj8rl4zr3m007zkt', 
    'session_data': 'eyJhYmMiOjEyMywieHl6IjoyMDAwfQ:1uxylf:TzRYH7EvGqDskqONSkyOIu_lnED0htQOuj-YjaJTfIM', 
    'expire_date': datetime.datetime(2025, 9, 29, 2, 16, 35, 276643, 
    tzinfo=datetime.timezone.utc)}
osoeo7f16xhlm1mdzj8rl4zr3m007zkt
eyJhYmMiOjEyMywieHl6IjoyMDAwfQ:1uxylf:TzRYH7EvGqDskqONSkyOIu_lnED0htQOuj-YjaJTfIM
2025-09-29 02:16:35.276643+00:00
{'abc': 123, 'xyz': 2000}
'''
